package com.smh.demo1.a22;

import com.smh.demo1.a22.pojo.User;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author shiminghui
 * @date 2025/5/2 18:00
 * @description: TODO
 */
@Controller
public class Controller1 {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
//        binder.addCustomFormatter(new MyDateFormatter());
    }

    @ModelAttribute
    public User getUser() {
        User user = new User();
        user.setName("zhang");
        user.setAge(18);
        // 设置生日
        user.setBirthDate(LocalDateTime.of(LocalDate.of(2004, 10, 26), LocalTime.of(0, 0)));
        return user;
    }


    @RequestMapping("/test")
    @ResponseStatus(HttpStatus.OK)
    public void test(@ModelAttribute("user") User user) {
        System.out.println(user);
    }

}
